import MusicManager from "../../../../MusicManager";
import BlackHolePredator from "../../../facility/priveteFacility/BlackHolePredator";
import { Killer } from "../../../funcObj/interface/HealthPoint";
import { FacilityType } from "../../../info/GameEnum";
import { Global } from "../../../info/Global";
import FlyerMissile from "../FlyerMissile";

const { ccclass, property } = cc._decorator;
/**
 * 黑洞
 */
@ccclass
export default class BlackHoleBullet extends FlyerMissile {

    _angle: number = 0;

    public get angle(): number {
        return this._angle;
    }

    public set angle(v: number) {
        this._angle = v;
    }
    maxScale: number;

    init(base: BlackHolePredator): void {
        super.init(base);
        this.node.scale = 0.3;
        this.getComponent(cc.Animation).play();
    }

    /**
     * 设定蓄力等级
     * @param progress 
     */
    setProgress(progress: number) {
        this.maxHp = this.atk = Math.ceil((this.flyerInfo.生命值 + Global.FacilityInfo[FacilityType.主基地].炮弹攻击.每等级加成[this.player.shellDamageBonusLevel]) * progress);
        this.currentHp = this.maxHp;
        this.viewRadius = Math.ceil(this.viewRadius * progress);
        this.blastRadius = Math.ceil(this.blastRadius * progress);
        this.maxScale = 1.8 * progress;
    }

    protected preDispatch(): void {
        MusicManager.instance.play(MusicManager.instance.blackHole, this.node, true);
        cc.tween(this.node)
            .to(1, { scale: this.maxScale })
            .start();
    }

    /**
     * 黑洞的攻击力 为当前的生命值
     * @param killer 
     * @returns 
     */
    reducedHp(killer: Killer): boolean {
        let boo = super.reducedHp(killer);
        let hpRate = this.hpProgress.progress;
        this.atk = Math.ceil(this.maxHp * hpRate);
        this.node.scale = this.maxScale * hpRate;
        return boo;
    }

}
